package com.mdxl.service;

import com.github.pagehelper.PageHelper;
import com.mdxl.Entity.Account;
import com.mdxl.dao.note.MbAccountDao;
import com.mdxl.dao.xml.MbAccountXmlDao;
import com.mdxl.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by chengjian on 2017/9/12.
 */
@Service
@EnableCaching
public class AccountService {
    @Autowired
    private MbAccountDao accountDao;
    @Autowired
    private MbAccountXmlDao accountXmlDao;
    public void insertAccount(Account account){
        accountDao.insertAccount(account);
    }
    public void deleteAccount(int id){
        accountDao.deleteAccount(id);
    }
    public void updateAccount(Account account){
        accountDao.updateAccount(account);
    }
    @Cacheable("accounts")
    public Account getAccount(String name){
        return accountDao.getAccount(name);
    }
    public void updateAccountXml(Account account){
       accountXmlDao.insertUserWithBackId(account);
    }
    public Object getAccountList(int page,int num){

        PageHelper.startPage(page, num);
        List<Account> accounts =accountDao.getAllAcc();
        //int countNums = itemMapper.countItem();
        PageBean<Account> pageData = new PageBean<>(page, num, 5);
        pageData.setItems(accounts);
        return pageData.getItems();

        /*TestPage TestPage = new TestPage();
        List<Account> selectAll = accountXmlDao.gainAllAccount();
        PageInfo<Account> pageInfo = new PageInfo<>(selectAll);
        return pageInfo;*/
    }
}
